<?php
session_start();
error_reporting(E_ERROR^E_WARNING^E_PARSE);
function __autoload($class_name) {
    require_once("inc/".$class_name . '.php');
}
$in_pmt = true;
require_once("config.php");
$msg = new Messages();
$db = new Database($db_host,$db_user,$db_pass,$db_name);
$date = new Date($db);
require("inc/functions.php");

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xml:lang="en" lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>Personal Money Tracker</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<link type="text/css" href="css/overcast/jquery-ui-1.8.9.custom.css" rel="stylesheet" />
	<link type="text/css" href="css/style.css" rel="stylesheet" />
	<script type="text/javascript" src="scripts/jquery.js"></script>
	<script type="text/javascript" src="scripts/jquery.ui.js"></script>
	<script type="text/javascript" src="scripts/script.js"></script>
	<script type="text/javascript">
	$('document').ready(function(){
	$('.date').datepicker({ firstDay: 1},{currentText: 'now!'});
	$('.date').datepicker( "option", "dateFormat", 'yy-mm-dd' );
	$('.date').datepicker("option","maxDate",'<?php echo $date->today_date;?>');
	$('.date').datepicker("option","minDate",'<?php echo $date->start_date;?>');
	$('.date').val("<?php echo $date->curr_date;?>");
	$("#products").sortable();
	$("#products").disableSelection();
	});
	</script>
</head>
<body>
<div id="header">Personal Money Tracker</div>

<?php
if(file_exists("install.php")){
	$p = "install";
}else if($_SESSION['is_logged'] == true){
	$p = $_GET["p"];
?>
<div id="menu">
<a href="index.php">Начало</a> | 
<a href="index.php?p=month">Преглед по месеци</a> | 
<a href="index.php?p=addcosts" >Добавяне на разходи за деня</a> |
<a href="index.php?p=products">Продукти</a> | 
<a href="index.php?p=logout">Излез</a>
</div>

<?php
	if(!$date->validate_date($date->curr_date)){
		$p = "date_error";
	}
} else {
	$p = "login";
}
?>
<div id="content">
<?php
switch($p){
	default : 
		include("summary.php");
	break;
	case "login":
		include("login.php");
	break;
	case "addcosts": 
		include("add_costs.php");
	break;
	case "products":
		include("products.php");
	break;
	case "month":
		include("month.php");
	break;
	case "day" :
		include("day.php");
	break;
	case "product":
		include("product.php");
	break;
	case "logout":
		session_destroy();
		$msg->write("Излязохте успешно! <a href=\"index.php\">Начало</a>");
	break;
	case "install":
		include("install.php");
	break;
	case "date_error":
		$msg->error("Проблем с подадената дата!");
	break;

} ?>
</div>
<div id="footer">
Chazz | 2011
</div>
</body>
</html>